package org.example.sort;

//选择排序算法
public class SelectionSort {
    public static void main(String[] args) {
        int[] arr = {10,15,97,15,64,75,0,23,78,62,197,2};
        for (int i = 0; i < arr.length; i++) {
            //设置目标索引
            int target =i;
            for (int j = i+1; j < arr.length; j++) {
                if (arr[target] > arr[j]) {
                    //更新最小索引
                    target = j;
                }
            }
            //若最小数值不是当前值在交换数据
            if (target != i) {
                int temp = arr[i];
                arr[i] = arr[target];
                arr[target] = temp;
            }
        }

        //打印输出
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }
}
